package com.tsu.mall.admin.service.impl;

import com.tsu.mall.common.VO.*;
import com.tsu.mall.admin.entity.Menu;
import com.tsu.mall.admin.exception.BusinessException;
import com.tsu.mall.admin.mapper.MenuMapper;
import com.tsu.mall.admin.service.IMenuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author tttttt
 * @since 2023-03-17
 */
@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements IMenuService {

    @Override
    public InitVO init() {
        //返回HomeInfoVo
        InitVO vo=new InitVO();
        HomeInfoVO homeInfoVO = new HomeInfoVO();
        homeInfoVO.setTitle("首页");
        homeInfoVO.setHref("/HomePage");
        vo.setHomeInfo(homeInfoVO);
        //返回LogoInfoVO
        LogoInfoVO logoInfo = new LogoInfoVO();
        logoInfo.setTitle("洛通商城");
        logoInfo.setHref("");
        logoInfo.setImage("images/logo.png");
        vo.setLogoInfo(logoInfo);
        //高级映射返回MenuInfoVO
        vo.setMenuInfo(baseMapper.menuInfo());
        return vo;
    }

    @Override
    public LayuiTableVO doList() {
        LayuiTableVO vo=new LayuiTableVO();
        vo.setData(baseMapper.doList());
        return vo;
    }

    @Override
    public ResultVO doDelete(Integer id) {
        ResultVO vo = new ResultVO();
        //id参数是要删除的菜单id
        //查看此菜单是否有子菜单
        List<Menu> list=baseMapper.selectByParentId(id);
        if(list.size() > 0){//有-不删除-错误提示
            throw new BusinessException("存在子菜单，不可以删除！");
        }else {//没有-删除
            baseMapper.deleteById(id);
            vo.setMsg("删除菜单信息成功!");
            return vo;
        }
    }

}
